<template>
  <div class="search-list" v-show="searches.length">
    <transition-group name="list" tag="ul">
      <li @click="selectItem(item)" class="search-item" v-for="item in searches" :key="item">
        <span class="text">{{ item }}</span>
        <span class="icon" @click.stop="deleteOne(item)">
          <i class="iconfont icon-delete"></i>
        </span>
      </li>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: 'SearchList',
  props: {
    searches: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    selectItem(item) {
      // 这是一个基础组件, 不做任何业务逻辑, 只负责派发事件出去给业务逻辑组件
      this.$emit('select', item)
    },
    deleteOne(item) {
      this.$emit('delete', item)
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../assets/css/variable.scss";
@import "../../assets/css/mixin.scss";

.search-list{
  .search-item{
    display: flex;
    align-items: center;
    height: 40px;
    overflow: hidden;
    &.list-enter-active, &.list-leave-active{
      transition: all 0.1s;
    }
    &.list-enter, &.list-leave-to{
      height: 0;
    }
    .text{
      flex: 1;
      color: $color-text-l;
    }
    .icon{
      @include extend-click();
      .icon-delete{
        font-size: $font-medium;
        color: $color-text-d;
      }
    }
  }
}
</style>